********************************************************************************
*****Replication code for Werner & Jacobs: Are populists sore losers?***********
clear
use bjpols_Werner&Jacobs_data


****DATA PREPARATION

*create pop scale without direct decision item (pop2)
sem (POPreduced -> pop1 pop3 pop4 pop5 pop6), latent (POPreduced) standardized
estat gof, stats(all)

gen pop_reduced = (pop1 + pop3 + pop4 + pop5 + pop6)/5

*education levels
rename w2_edu edu
recode edu (2=1 "lower") (3=2 "middle") (4=2) (5=3 "higher") (6=3),gen(w2_edu)
rename w3_edu w3_educ
recode w3_educ (2=1 "lower") (3=2 "middle") (4=2) (5=3 "higher") (6=3), gen(w3_edu)

*labelling
label var w2_age "age"
label var pop_reduced "populist attitudes"
label var w2_out_pref "policy pref. (ref: no)"
label var w2_mp_s2 "majority perception"
label var w2_trust "political trust"
label var w2_age "age"
label var w2_gender "gender (ref: male)"
label var w2_edu "education (ref: lower)"
label var w3_loser "decision loser"
label var w3_party "party pref. (ref: VVD)"


********************************************************************************
***************ANALYSIS*********************************************************

*create analytical sample for main analysis
reg w2_sup_s i.w2_mp_s2 i.w2_out_pref w2_trust w2_age w2_gender i.w2_edu w3_da pop1 pop3 pop4 pop5 pop6 w2_mp_s2 i.w2_out_pref w2_trust i.w2_edu i.w2_party w3_party w3_loser
keep if e(sample)

***Preferences for the specific referendum

*H1
eststo, title ("Main effect"): reg w2_sup_s pop_reduced i.w2_out_pref w2_mp_s2 w2_trust w2_age w2_gender i.w2_edu i.w3_party  
*H2a
eststo, title ("Interaction policy preference"): reg w2_sup_s c.pop_reduced##i.w2_out_pref w2_mp_s2 w2_trust w2_age w2_gender i.w2_edu i.w3_party 
*H2b
eststo, title ("Interaction majority perception"): reg w2_sup_s w2_out_pref c.pop_reduced##i.w2_mp_s2 w2_trust w2_age w2_gender i.w2_edu i.w3_party 

**Appendix: Table A4, H1, H2a H2b
estout est* ///
using "popref_Table1a.xls", replace  ///
title ("Table A4.Regression of Support for Referendums (Pre-Wave)") ///
note("Note: Estimates are unstandardized regression coeffcients") ///
cells((b(fmt(2) label(Coef)) p(fmt(3)) se(fmt(2)label(Std. err.))))   /// 
stats(r2 N, fmt(2 %9.0f) labels("R2" "N")) ///
drop (_cons) nobaselevels interaction ("x") ///
label  varlabels (w2_out_pref "policy preference" pop_reduced "populist attitudes" ///
w2_mp_s2 "majority perception" w2_trust "political trust" w2_age "age" ///
w2_gender "gender (female)" w2_edu "education" w3_part "party preference") wrap 
est clear

*FIGURE 1: coefplot H1, H2a, H2b
eststo MI: reg w2_sup_s c.pop_reduced i.w2_out_pref i.w2_mp_s2 w2_trust w2_age w2_gender i.w2_edu i.w3_party  
eststo MII: reg w2_sup_s c.pop_reduced##i.w2_out_pref i.w2_mp_s2 w2_trust w2_age w2_gender i.w2_edu i.w3_party 
eststo MIII: reg w2_sup_s i.w2_out_pref c.pop_reduced##i.w2_mp_s2 w2_trust w2_age w2_gender i.w2_edu i.w3_party 

coefplot MI || MII || MIII, drop(*.w3_party _cons) xline(0, lp(solid)) ///
grid(none) byopts(row(1)) xlabel(,labsize(medium)) ylabel(,labsize(medium))

*FIGURE 2: visualize interaction H2a
reg w2_sup_s c.pop_reduced##i.w2_out_pref w2_mp_s2 w2_trust w2_age w2_gender i.w2_edu i.w3_party 
margins, dydx(w2_out_pref) at(pop_reduced=(1(.5)5)) vsquish 
marginsplot, title("support for policy proposal") recastci(rarea) ciopt(color(gs13)) yline(0) name(g1, replace)

reg w2_sup_s i.w2_out_pref c.pop_reduced##i.w2_mp_s2 w2_trust w2_age w2_gender i.w2_edu i.w3_party 
margins, dydx(w2_mp_s2) at(pop_reduced=(1(.5)5)) vsquish
marginsplot, title("majority perceptions") recastci(rarea) ciopt(color(gs13)) yline(0)  name(g2, replace)

graph combine g1 g2, iscale(*1.6) xsize(8) ycommon


***Decision Acceptance

*Appendix: Table A5, H3
eststo, title ("all"):reg w3_da i.w3_loser pop_reduced w2_trust  w2_gender w2_age i.w2_edu i.w3_party

eststo, title ("decision loser"):reg w3_da pop_reduced w2_trust  w2_gender w2_age i.w2_edu i.w3_party  if w3_loser ==1

estout est* ///
using "popref_Table2.xls", replace  ///
title ("Table 2.Regression of Acceptance of the Referendum Outcome (Post-Wave)") ///
note("Note: Estimates are unstandardized regression coeffcients") ///
cells((b(fmt(2) label(Coef)) p(fmt(3)) se(fmt(2)label(Std. err.))))   /// 
stats(r2 N, fmt(2 %9.0f) labels("R2" "N")) ///
drop (_cons) nobaselevels interaction ("x") ///
label  varlabels ( pop_reduced "populist attitudes" ///
w2_trust "political trust" w2_age "age" ///
w2_gender "gender (female)" w2_edu "education" w3_part "party preference") wrap 
est clear

*FIGURE 3: coefplot H3
eststo MIV: reg w3_da i.w3_loser pop_reduced w2_mp_s2 w2_trust  w2_gender w2_age i.w2_edu i.w3_party
eststo MV: reg w3_da pop_reduced w2_mp_s2 w2_trust  w2_gender w2_age i.w2_edu i.w3_party  if w3_loser ==1

coefplot MIV || MV, drop(*.w3_party _cons)  ///
xline(0) byopts(row(1)) xlabel(,labsize(med)) ylabel(,labsize(med))

********************************************************************************
****************APPENDIX********************************************************

*DESCRIPTIVES 

fre w2_out_pref
fre w3_party
fre w2_gender w2_edu 
sum w2_age if w2_age<=40
sum w2_age if w2_age>=40 & w2_age <=60
sum w2_age if w2_age>=60

tabstat pop_reduced, by(w3_party)
tabstat w3_loser, by(w3_party)

tabstat pop_reduced, by(w3_loser)
histogram pop_reduced if w3_loser==1
histogram pop_reduced if w3_loser==0


*ROBUSTNESS CHECKS


*A7. full sample acceptance
***reload data to get full sample
clear
use bjpols_Werner&Jacobs_data

*create pop scale without direct decision item (pop2)
sem (POPreduced -> pop1 pop3 pop4 pop5 pop6), latent (POPreduced) standardized
estat gof, stats(all)
gen pop_reduced = (pop1 + pop3 + pop4 + pop5 + pop6)/5

*education levels
rename w3_edu w3_educ
recode w3_educ (2=1 "lower") (3=2 "middle") (4=2) (5=3 "higher") (6=3), gen(w3_edu)

*analysis

eststo, title ("all"):reg w3_da i.w3_loser pop_reduced i.w3_edu w3_gender w3_age i.w3_party
*when lost
eststo, title ("decision loser"):reg w3_da pop_reduced i.w3_edu w3_gender w3_age i.w3_party  if w3_loser ==1

estout est* ///
using "popref_TableA4.xls", replace  ///
title ("Table A7.Regression of Acceptance of the Referendum Outcome (Post-Wave) full sample") ///
note("Note: Estimates are unstandardized regression coeffcients") ///
cells((b(fmt(2) label(Coef)) p(fmt(3)) se(fmt(2)label(Std. err.))))   /// 
stats(r2 N, fmt(2 %9.0f) labels("R2" "N")) ///
drop (_cons) nobaselevels interaction ("x") ///
label  varlabels ( pop_reduced "populist attitudes" ///
w2_trust "political trust" w3_age "age" ///
w3_gender "gender (female)" w3_edu "education" w3_party "party preference") wrap 
est clear


*A8.full pop scale preferences

***go back to analytical sample

*education levels
rename w2_edu edu
recode edu (2=1 "lower") (3=2 "middle") (4=2) (5=3 "higher") (6=3),gen(w2_edu)

*labelling
label var w2_age "age"
label var pop_reduced "populist attitudes"
label var w2_out_pref "policy pref. (ref: no)"
label var w2_mp_s2 "majority perception"
label var w2_trust "political trust"
label var w2_age "age"
label var w2_gender "gender (ref: male)"
label var w2_edu "education (ref: lower)"
label var w3_loser "decision loser"
label var w3_party "party pref. (ref: VVD)"

*create analytical sample for main analysis
reg w2_sup_s i.w2_mp_s2 i.w2_out_pref w2_trust w2_age w2_gender i.w2_edu w3_da pop1 pop3 pop4 pop5 pop6 w2_mp_s2 i.w2_out_pref w2_trust i.w2_edu i.w2_party w3_party w3_loser
keep if e(sample)

*analysis
gen pop = (pop1 + pop2 + pop3 + pop4 +pop5 +pop6)/6

eststo, title ("Main effect"): reg w2_sup_s pop i.w2_out_pref w2_mp_s2 w2_trust w2_age w2_gender i.w2_edu i.w3_party  
eststo, title ("Interaction policy preference"): reg w2_sup_s c.pop##i.w2_out_pref w2_mp_s2 w2_trust w2_age w2_gender i.w2_edu i.w3_party 
eststo, title ("Interaction majority perception"): reg w2_sup_s w2_out_pref c.pop##i.w2_mp_s2 w2_trust w2_age w2_gender i.w2_edu i.w3_party 


estout est* ///
using "popref_TableA5.xls", replace  ///
title ("Table A8.Regression of Support for Referendums (Pre-Wave) with full populism scale") ///
note("Note: Estimates are unstandardized regression coeffcients") ///
cells((b(fmt(2) label(Coef)) p(fmt(3)) se(fmt(2)label(Std. err.))))   /// 
stats(r2 N, fmt(2 %9.0f) labels("R2" "N")) ///
drop (_cons) nobaselevels interaction ("x") ///
label  varlabels (w2_out_pref "policy preference" pop "populist attitudes" ///
w2_mp_s2 "majority perception" w2_trust "political trust" w2_age "age" ///
w2_gender "gender (female)" w2_edu "education" w3_part "party preference") wrap 
est clear


*A9. full pop scale acceptance

eststo, title ("all"):reg w3_da i.w3_loser pop w2_trust i.w2_edu w2_gender w2_age i.w3_party
*when lost
eststo, title ("decision loser"):reg w3_da pop w2_trust i.w2_edu w2_gender w2_age i.w3_party  if w3_loser ==1

estout est* ///
using "popref_TableA6.xls", replace  ///
title ("Table A9.Regression of Acceptance of the Referendum Outcome (Post-Wave) with full populism scale") ///
note("Note: Estimates are unstandardized regression coeffcients") ///
cells((b(fmt(2) label(Coef)) p(fmt(3)) se(fmt(2)label(Std. err.))))   /// 
stats(r2 N, fmt(2 %9.0f) labels("R2" "N")) ///
drop (_cons) nobaselevels interaction ("x") ///
label  varlabels ( pop "populist attitudes" ///
w2_trust "political trust" w2_age "age" ///
w2_gender "gender (female)" w2_edu "education" w3_part "party preference") wrap 
est clear


*A10 interaction with issue importance
*include issue importance in analytical sample

eststo, title ("all"):reg w3_da i.w3_loser c.pop_reduced##c.w2_ii w2_trust i.w2_edu w2_gender w2_age i.w3_party
*when lost
eststo, title ("decision loser"):reg w3_da c.pop_reduced##c.w2_ii w2_trust i.w2_edu w2_gender w2_age i.w3_party  if w3_loser ==1

estout est* ///
using "popref_TableA12.xls", replace  ///
title ("Table A10. Interaction between Pop. Attitudes and Issue Importance explaining decision acceptance (Post-Wave)") ///
note("Note: Estimates are unstandardized regression coeffcients") ///
cells((b(fmt(2) label(Coef)) p(fmt(3)) se(fmt(2)label(Std. err.))))   /// 
stats(r2 N, fmt(2 %9.0f) labels("R2" "N")) ///
drop (_cons) nobaselevels interaction ("x") ///
label  varlabels ( pop_reduced "populist attitudes" ///
w2_trust "political trust" w2_age "age" ///
w2_gender "gender (female)" w2_edu "education" w3_part "party preference") wrap 
est clear


****ADDITIONAL HYPOTHESIS
*H4 difference in preferences for referendums
*create variable for changes in support for referendums
gen sup_diff = w3_sup_g - w2_sup_g
fre sup_diff
sum sup_diff
ttest w3_sup_g == w2_sup_g


eststo, title ("all"): reg sup_diff i.w3_loser pop_reduced i.w2_mp_s2 w2_trust i.w2_edu w2_gender w2_age i.w3_party 
eststo, title ("decision losers"): reg sup_diff  pop_reduced i.w2_mp_s2 w2_trust i.w2_edu w2_gender w2_age i.w3_party if w3_loser==1

estout est* ///
using "popref_Table3.xls", replace  ///
title ("Table A11.Regression of General Support for Referendums") ///
note("Note: Estimates are unstandardized regression coeffcients") ///
cells((b(fmt(2) label(Coef)) p(fmt(3)) se(fmt(2)label(Std. err.))))   /// 
stats(r2 N, fmt(2 %9.0f)  labels("R2" "N")) nolz ///
drop (_cons) nobaselevels interaction ("x")  ///
label  varlabels ( pop "populist attitudes" i.w3_loser "decision loser" ///
i.w2_mp_s2 "outcome expectation (winning)" w2_trust "political trust" w2_age "age" ///
w2_gender "gender (female)" w2_edu "education" w3_party "party preference") wrap 
est clear


eststo MVI: reg sup_diff i.w3_loser pop_reduced i.w2_mp_s2 w2_trust i.w2_edu w2_gender w2_age i.w3_party 
eststo MVII:reg sup_diff  pop_reduced i.w2_mp_s2 w2_trust i.w2_edu w2_gender w2_age i.w3_party if w3_loser==1

coefplot MVI || MVII, drop(*.w3_party _cons)  xline(0, lp(solid)) byopts(row(1)) xlabel(,labsize(med)) ylabel(,labsize(med)) grid(none)




